package cn.com.code.design.factory;

import cn.com.code.design.utils.ClassLoaderUtils;
import cn.com.code.design.workshop.ICacheAdapter;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * @author zhengpei
 * @date 2021/9/13
 */
public class JDKInvocationHandler implements InvocationHandler {

  private ICacheAdapter iCacheAdapter;

  public JDKInvocationHandler(ICacheAdapter iCacheAdapter) {
    this.iCacheAdapter = iCacheAdapter;
  }

  @Override
  public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    return ICacheAdapter.class.getMethod(method.getName(), ClassLoaderUtils.getClazzByArgs(args)).invoke(iCacheAdapter, args);
  }

}
